
#ifndef _SPI_H_
#define _SPI_H_

#include	"stm32f0xx.h"
#include	"data_type.h"

#define	SPI_RDY	0u
#define	EXCH_SIZE_MAX	(116u)  

#define	EXCH_RTN_OK		(0u)
#define	EXCH_RTN_BUF_OV	(1u)

void exch_spi_init(bool_t b8_is_master);
void exch_init_val(void);
uint8_t exch_set_dat(const volatile uint8_t *u8p_dat, uint8_t u8_len);
uint8_t exch_get_dat(volatile uint8_t *u8p_dat, uint8_t u8_len);

bool_t exch_spi_is_busy(void);
void exch_spi_disable(void);
void exch_spi_enable(bool_t b8_is_master);

bool_t exch_get_slave_trigger(void);
void exch_set_slave_trigger(bool_t b8_ready);
bool_t exch_get_master_ready(void);
void exch_set_master_ready(bool_t b8_ready);

uint8_t exch_get_status(void);

/* void exch_spi_test(bool_t b8_is_master); */

/* Communication boards SPIx Interface */
#define DRE_SPI_TX_DMA_CHANNEL	DMA1_Channel3
#define DRE_SPI_TX_DMA_FLAG_TC	DMA1_FLAG_TC3
#define DRE_SPI_TX_DMA_FLAG_GL	DMA1_FLAG_GL3
#define DRE_SPI_RX_DMA_CHANNEL	DMA1_Channel2
#define DRE_SPI_RX_DMA_FLAG_TC	DMA1_FLAG_TC2
#define DRE_SPI_RX_DMA_FLAG_GL	DMA1_FLAG_GL2

#define DRE_DMA_CLK		RCC_AHBPeriph_DMA1

#define DRE_SPI			SPI1
#define DRE_SPI_CLK		RCC_APB2Periph_SPI1
#define DRE_SPI_IRQn		SPI1_IRQn
#define DRE_SPI_IRQHandler	SPI1_IRQHandler


#endif /* __SPI_H */
